import Foundation

public enum Month: String, CaseIterable, Codable {
    case jan = "BearCalendar.month.jan"
    case feb = "BearCalendar.month.feb"
    case mar = "BearCalendar.month.mar"
    case apr = "BearCalendar.month.apr"
    case may = "BearCalendar.month.may"
    case jun = "BearCalendar.month.jun"
    case jul = "BearCalendar.month.jul"
    case aug = "BearCalendar.month.aug"
    case sep = "BearCalendar.month.sep"
    case oct = "BearCalendar.month.oct"
    case nov = "BearCalendar.month.nov"
    case dec = "BearCalendar.month.dec"
    
    public func title(_ language: Language = Preference.shared.language) -> String {
        var bundle: Bundle = .module
        if let path = Bundle.module.path(forResource: language.locale.identifier, ofType: "lproj") {
            bundle = Bundle(path: path) ?? .module
        }
        return switch self {
        case .jan: NSLocalizedString(rawValue, bundle: bundle, comment: "")
        case .feb: NSLocalizedString(rawValue, bundle: bundle, comment: "")
        case .mar: NSLocalizedString(rawValue, bundle: bundle, comment: "")
        case .apr: NSLocalizedString(rawValue, bundle: bundle, comment: "")
        case .may: NSLocalizedString(rawValue, bundle: bundle, comment: "")
        case .jun: NSLocalizedString(rawValue, bundle: bundle, comment: "")
        case .jul: NSLocalizedString(rawValue, bundle: bundle, comment: "")
        case .aug: NSLocalizedString(rawValue, bundle: bundle, comment: "")
        case .sep: NSLocalizedString(rawValue, bundle: bundle, comment: "")
        case .oct: NSLocalizedString(rawValue, bundle: bundle, comment: "")
        case .nov: NSLocalizedString(rawValue, bundle: bundle, comment: "")
        case .dec: NSLocalizedString(rawValue, bundle: bundle, comment: "")
        }
    }
    
    public var value: Int {
        switch self {
        case .jan: 1
        case .feb: 2
        case .mar: 3
        case .apr: 4
        case .may: 5
        case .jun: 6
        case .jul: 7
        case .aug: 8
        case .sep: 9
        case .oct: 10
        case .nov: 11
        case .dec: 12
        }
    }
}
